#include "readerwriterqueue.h"
//#include "./common/simplethread.h"

using namespace moodycamel;

#include <iostream>	
#include <cstdlib>
#include <exception>
#include <fstream>
#include <cstdlib>	

typedef enum {
    LOGFILE_OPEN = 1,
    LOGFILE_CLOSE,
    LOGFILE_WRITE
}LOGFILE_ACTION;

struct LogMsg {
    LogMsg(LOGFILE_ACTION _action, std::string _fileName, std::string _log) :
        op(_action), fileName(_fileName), log(_log)
    {
    }

public:
    LOGFILE_ACTION  op;
    std::string fileName;
    std::string log;


    ~LogMsg() {
        std::cout << "" << std::endl;
    }
};

void test_concurrent()
{
    LogMsg* msg = nullptr;

    BlockingReaderWriterQueue<LogMsg *, 4> q(1024);
    std::cout << q.size_approx() << std::endl;
    q.wait_dequeue_timed(msg, 1000000);

    q.enqueue(new LogMsg(LOGFILE_OPEN, "1.txt", "test"));
    q.enqueue(new LogMsg(LOGFILE_OPEN, "1.txt", ""));
    std::cout << q.size_approx() << std::endl;

    //q.try_dequeue(msg);
    q.wait_dequeue_timed(msg, 1000);
    if (msg) {
        delete msg;
        msg = nullptr;
    }

    q.wait_dequeue_timed(msg, 1000);

    if(msg) delete msg;
    std::cout << q.size_approx() << std::endl;
}

int main(int argc, char** argv)
{
    test_concurrent();

    return 0;
}